<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .router-link-active{
      background-color: rgb(218, 22, 142);
    }
  </style>
</head>

<body>
  <div id="app">
    <!-- 跳转路由组件 -->
    <router-link tag="button" to="/home">首页</router-link>
    <router-link tag="button" to="/news">新闻页</router-link>
    <router-link tag="button" to="/about">关于我们</router-link>
    <!-- 在 视图上 指定路由组件出口 -->
    <router-view></router-view>
    
  </div>
  <script src="./vue.js"></script>
  <script src="./vue-router.js"></script>
  <script>
    // 准备路由组件对象 为了注册路由组件
    const Home = {
      template: `
        <div>
          <h2>我是首页</h2>  
        </div>
      `
    }
    const News = {
      template: `
        <div>
          <h2>我是新闻页</h2>  
        </div>
      `
    }
    const About = {
      template: `
        <div>
          <h2>关于我们</h2>  
        </div>
      `
    }
    // 创建一个 router 对象
    const routes = [
      {
        path: '/home',
        component: Home
      },
      {
        path: '/news',
        component: News
      },
      {
        path:'/about',
        component: About
      }
    ]
    const router = new VueRouter({
      // routes 路由规则
      routes
    });
    // 将router对象 挂载到实例上
    const vm = new Vue({
      el: "#app",
      router
    })
  </script>
</body>

</html>